package com.mainframe;

import java.awt.Container;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JTextField;

import com.data.Message;
import com.data.TAG;

public class DlgPressureNo {
	
	public static JDialog dlg;
	private JTextField tfd_low;
	private JTextField tfd_high;
	private JButton btn_pressureno_sure;
	private JLabel lbl_low;
	private JLabel lbl_high;
	private JProgressBar pgb_pressureNo;
	
	public DlgPressureNo(Frame jf) {
		dlg = new JDialog(jf,"无源调整",true);
		initComponents();
		
	}
	private void initComponents() {
		
		dlg.setSize(400, 300);
		Container c=dlg.getContentPane();  
        c.setLayout(null);  
		
        lbl_low = new JLabel("零点压力值");
		lbl_low.setBounds(new Rectangle(30, 50, 100, 30));
		
		lbl_high = new JLabel("满程压力值");
		lbl_high.setBounds(new Rectangle(200, 50, 100, 30));
		
		tfd_low = new JTextField();
		tfd_low.setBounds(new Rectangle(30, 100, 100, 30));
		
		tfd_high = new JTextField();
		tfd_high.setBounds(new Rectangle(200, 100, 100, 30));
		
		pgb_pressureNo = new JProgressBar();
		pgb_pressureNo.setBounds(new Rectangle(30, 240, 300, 30));
		
		btn_pressureno_sure = new JButton("无源压力调整");
		btn_pressureno_sure.setBounds(new Rectangle(200, 200, 120, 30));
		btn_pressureno_sure.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				new Thread(){
					@Override
					public void run() {
						int count = 0;
						while(count++<4){
							pgb_pressureNo.setValue(25*count);
							try {
								Thread.sleep(900);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						}
					}
				}.start();
				Message.msg.setPvHigh(Float.parseFloat(tfd_high.getText()));
				Message.msg.setPvLow(Float.parseFloat(tfd_low.getText()));
				Message.msg.setTag(TAG.MSG_PRESURE_NO);
			}
		});
		
		c.add(btn_pressureno_sure);
		c.add(lbl_high);
		c.add(lbl_low);
		c.add(tfd_high);
		c.add(tfd_low);
		c.add(pgb_pressureNo);		
	}
	
}
